package edu.gatech.oad.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.Window;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import edu.gatech.oad.records.TreatmentRecord;
import edu.gatech.oad.schedule.Appointment;
import edu.gatech.oad.schedule.AppointmentController;
import edu.gatech.oad.user.AccountsController;
import edu.gatech.oad.user.Doctor;
import edu.gatech.oad.user.MedicalPersonnelAvailability;
import edu.gatech.oad.user.MedicalPersonnelSchedule;
import edu.gatech.oad.user.Patient;
import edu.gatech.oad.user.SystemAdministrator;

/**
 * Main class, starts the progra,
 * @author Joey Slater
 * @version 1.00
 */
public class Main{
	private static final long serialVersionUID = 1L;
	/**
	 * Main arguments
	 * @param args the code of the program
	 */
	public static void main(String[] args) {
		
		try {
		    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
		        if ("Nimbus".equals(info.getName())) {
		            UIManager.setLookAndFeel(info.getClassName());
		            break;
		        }
		    }
		} catch (UnsupportedLookAndFeelException e) {
		    // handle exception
		} catch (ClassNotFoundException e) {
		    // handle exception
		} catch (InstantiationException e) {
		    // handle exception
		} catch (IllegalAccessException e) {
		    // handle exception
		}
		
		JFrame frame = new JFrame(); //The main frame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
		frame.setLayout(new BorderLayout());
        frame.setTitle("M.U.F.A.S.A. : Simba Build");
        JFrame.setDefaultLookAndFeelDecorated(true);  
        MainPanel mainPanel = new MainPanel(frame); //makes sure the main panel can access the frame
        frame.add(mainPanel, BorderLayout.CENTER);
        frame.setResizable(true);
        addUsers();
        frame.getContentPane();
        frame.pack();
		frame.setVisible(true); 
		
	}


	public static void addUsers(){
		Patient patient = AccountsController.sharedController().addPatientForUsername("A"); //adds some people (testing purposes)
		patient.setPassword("B");
		patient.setFirstName("Joey");
		patient.setLastName("Slater");
		patient.setEmailAddress("joeyslater@gatech.edu");
		List<String> reasons = new ArrayList<String>();
		reasons.add("Ouch");
		reasons.add("No");
		patient.getPatientHistory().addTreatmentRecord(new TreatmentRecord(new Appointment(Calendar.getInstance().getTime(), reasons)));
		Doctor doctor = AccountsController.sharedController().addDoctorForUsername("Doc");
		doctor.setPassword("doc");
		doctor.setFirstName("James");
		doctor.setLastName("Wilson");
		Doctor doctor1 = AccountsController.sharedController().addDoctorForUsername("House");
		doctor1.setPassword("Cuddy");
		doctor1.setFirstName("Greg");
		doctor1.setLastName("House");
		Doctor doctor2 = AccountsController.sharedController().addDoctorForUsername("Holmes");
		doctor2.setPassword("Sherlock");
		doctor2.setFirstName("Sherlock");
		doctor2.setLastName("Home");
		List<MedicalPersonnelAvailability> data = new ArrayList<MedicalPersonnelAvailability>();
		for(int i = 1; i < 31; i++){
			MedicalPersonnelAvailability workday = new MedicalPersonnelAvailability(Calendar.getInstance().getTime(), doctor1);
			workday.setDay(i);
			data.add(i-1, workday);
		}
		MedicalPersonnelSchedule mps = new MedicalPersonnelSchedule(data);
		doctor1.setSchedule(mps);
		Appointment app = new Appointment(new Date(), reasons);
		Calendar cal = GregorianCalendar.getInstance();
		cal.set(6, Calendar.HOUR);
		Appointment appt = new Appointment(cal.getTime(), reasons);

		AppointmentController apc = new AppointmentController(patient, doctor1);
		apc.save(app);
		apc.save(appt);
		
		SystemAdministrator admin = AccountsController.sharedController().addSystemAdministratorForUsername("admin");
		admin.setPassword("mufasa.admin");
	}
}